<?php

# I N C L U D E S
include "../site_specific/project.php";
include "../includes/constants.php";
include "../site_specific/external_constants.php";
include "../includes/phpmailer/class.phpmailer.php";
include "../includes/phpmailer/class.smtp.php";
include "../includes/utilities.php";
include "../includes/pages.php";
include "../includes/database.php";
include "../includes/users.php";
include "../includes/date.php";
include "../includes/files.php";
include "../includes/text.php";
include "../includes/tableproperties.php";
include "../includes/shopping_cart.php";
include "../includes/init_front.php";

#Get id from url
$course_id = $_GET["id"];

#main output of html page
static $OUPUT_CONTENT ="";

$content_left_side ="";

$page_path = "";

#This value store the current page id
$current_id = "";

$course_number = str_replace('mres_','',$course_id);

echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
echo "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en-AU\" xml:lang=\"en-AU\">\n";
echo "<!-- Created by Cameron Morrow for Zone 4 -->\n";
echo "<head>\n";
echo "\t<title>" . $PROJECT_TITLE . " - " . $PAGE_NAME . "</title>\n";
echo "\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />\n";
echo "\t<script language=\"javascript\" type=\"text/javascript\" src=\"../site_specific/assets/scripts/tct.js\"></script>\n";
echo "\t<style type=\"text/css\">\n";
echo "\t\t@import url(\"../site_specific/assets/styles/main.css\");\n";
echo "\t</style>\n";
echo "</head>\n";

echo "<body>";

# Start container
echo "<div id=\"container\">";

	# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	# H E A D E R
	# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	echo "<div id=\"header\">";
	echo "<h1>" . $PROJECT_TITLE . " - " . $PAGE_NAME . "</h1>\n";
	echo "</div>";

echo "<div id=\"nav\">\n";
echo "<hr/>";
echo "</div>";

echo "<div style=\"margin-bottom:auto;margin-right:auto;margin-left:50px;margin-top:50px;\">";

echo "<div id =\"html_column\" style=\"overflow:scroll;height:400px;width:800px;border-style:solid;
border-width:1px;\">";

IterationPages($course_id);

echo "</div>";	

echo "<span style=\"color:red;font-size:xx-large;\">operation finished!!!</span><br/><a href=\"../files/generateZipSample1.php?id=".$course_id."\">Generate Zip</a>&nbsp;&nbsp;<br/>";

echo "</div>";

echo "</div>";

echo "</body>";

echo "</html>";

//$index_content = "<a href=\"html/".$course_id."_m1.html\">go to index page</a>";
//
//if(deleteFile("../files/".$course_id."/index.html")){
//		
//	echo "../files/".$course_id."/index.html has been deleted"."<br/>";
//}
//else{
//	
//	echo "../files/".$course_id."/index.html deleting is not successful"."<br/>";
//}
//
////echo $PRINT_OUTPUT;
//if(createFile("../files/".$course_id."/index.html",$index_content)){
//
//	echo "../files/".$course_id."/index.html has been created"."<br/>";		 
//}
//else{
//	
//	echo "../files/".$course_id."/index.html creation request has been rejected"."<br/>";
//}


//GenerateZip($course_id);

function GenerateZip($course_id){
	
	$zip_file = $course_id.".zip";
	
	$images = $course_id;
	
	echo "files:".$images."<br/>";
	
	if ($handle = opendir($images))  
	{
		echo "zip"."<br/>";
		$zip = new ZipArchive();
		
		if ($zip->open($zip_file, ZIPARCHIVE::CREATE)!==TRUE) 
		{
			exit("cannot open <$filename>\n");
		}
		
		echo "zip_file:".$zip_file;
		
		while (false !== ($file = readdir($handle))) 
		{   
			echo $file."<br/>";
			if($handle1 = opendir($images.'/'.$file)){
				
				if($file != '.' && $file != '..' && $file != ''){
					
					while (false !== ($file1 = readdir($handle1))) {
						
						echo "====".$file1."<br/>";
						if($handle2 = opendir($images.'/'.$file.'/'.$file1)){
							
							if($file1 != '.' && $file1 != '..' && $file1 != ''){
								
								echo "====".$file1."<br/>";
								
								while (false !== ($file2 = readdir($handle2))){
									
									if($file2 != '.' && $file2 != '..' && $file2 != ''){
											
										if($zip->addFile($images.'/'.$file.'/'.$file1.'/'.$file2)){
											
											echo $images.'/'.$file.'/'.$file1.'/'.$file2."has been added successfully<br/><br/>";
										}
										else{
											
											echo $images.'/'.$file.'/'.$file1.'/'.$file2."The transfer for $file1 has failure<br/><br/>";
										}
									}
								}
							}
						}
						else{
							if($file1 != '.' && $file1 != '..' && $file1 != ''){
								
								if($zip->addFile($images.'/'.$file.'/'.$file1)){
												
									echo $images.'/'.$file.'/'.$file1."has been added successfully<br/><br/>";
								}
								else{
												
									echo $images.'/'.$file.'/'.$file1."The transfer for $file1 has failure<br/><br/>";
								}
							}
						}
					}
				}
			}
			else{
				if($file != '.' && $file != '..' && $file != ''){
					
					if($zip->addFile($images.'/'.$file)){
												
						echo $images.'/'.$file."has been added successfully<br/><br/>";
					}
					else{
									
						echo $images.'/'.$file."The transfer for $file1 has failure<br/><br/>";
					}
				}
			} 
		}
		closedir($handle);
		$zip->close();
	}
}

function IterationPages($id = ''){
	
	global $PAGES;
	
	global $USER;
	
	global $current_id;
	
	$top_level_pages = $PAGES -> getChildrenOfPage($id);
	
	generateHTMLFile($id);

	if(count($top_level_pages)>0){
	
		# For each
		foreach ($top_level_pages -> getPageIDs() as $nav_page_id) {
		
			# Get page details
			$nav_page = $top_level_pages -> getPage($nav_page_id);
		
			# Get list of groups authorized to view this page
			$nav_page_authorized = explode(",", $nav_page -> getData("p_access"));
			
			# Get List of groups of users
			$nav_group_authorized= explode(",", $USER -> getGroup());
		
			# Ensure it can be viewed at current authorization
			$nav_page_authorized = $USER -> isUserAuthorized($PAGES -> getAuthorizedGroups($nav_page_id));
		
			# Ensure it's in the navigation
			//$nav_page_in_navigation = ($nav_page -> getData("p_innavigation") == "1");
		
			# Get class for <li> item
			$item_class = ($nav_page -> getID() == $PAGES -> getPageAtDepth($PAGE_ID, 0)) ? array("active") : array();
		
			if ($nav_page_authorized) {
				
				$current_id = $nav_page_id;
				
				IterationPages($nav_page_id);	
				
				echo "<script type=\"text/javascript\">var objdiv= document.getElementById('html_column');objdiv.scrollTop = objdiv.scrollHeight;</script>";


				
			}
		}
	}		
}

function generateHTMLFile($id){
	
	global $PROJECT_TITLE;
	global $PAGE_NAME;
	global $course_id;
	global $PAGE_ID;
	global $PAGES;
	global $content_left_side;
	global $page_path;
	global $current_id;
	global $PROJECT_DB_TABLES;
	global $USER;

	$PRINT_OUTPUT = "";
	
	$PRINT_OUTPUT .= "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
	$PRINT_OUTPUT .= "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en-AU\" xml:lang=\"en-AU\">\n";
	$PRINT_OUTPUT .= "<!-- Created by Cameron Morrow for Zone 4 -->\n";
	$PRINT_OUTPUT .= "<head>\n";
	$PRINT_OUTPUT .= "\t<title>" . $PROJECT_TITLE . " - " . $PAGE_NAME . "</title>\n";
	$PRINT_OUTPUT .= "\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />\n";
	$PRINT_OUTPUT .= "\t<script language=\"javascript\" type=\"text/javascript\" src=\"../js/tct.js\"></script>\n";
	$PRINT_OUTPUT .= "\t<style type=\"text/css\">\n";
	$PRINT_OUTPUT .= "\t\t@import url(\"../css/main.css\");\n";
	$PRINT_OUTPUT .= "\t</style>\n";
	$PRINT_OUTPUT .= "</head>\n";

	$PRINT_OUTPUT .= "<body onload=\"parseImagePopups();\">\n";

	# Start container
	$PRINT_OUTPUT .= "<div id=\"main_body\">";

	# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	# H E A D E R
	# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	$PRINT_OUTPUT .= "<div id=\"header1\">";
	$PRINT_OUTPUT .= "<br/>";
	$PRINT_OUTPUT .= "<a href=\"http://mrt2.cai.uq.edu.au\"><img src=\"../site_specific/assets/images/index/uqlogo.png\"/></a>";
	$PRINT_OUTPUT .= "</div>";

	
	# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	# M A I N   C O N T E N T
	# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
			
	$PRINT_OUTPUT .= "<div id=\"menu1\">\n";
	$PRINT_OUTPUT .= "<br/>";
	$PRINT_OUTPUT .= "<div>";
	$PRINT_OUTPUT .= "<TABLE>";
	
	
	$flag_list_end = false; //this flag is used to judge whether the list will be ended or not.
	
	$page_path = $PAGES -> getPathToPage($id);
	
	$length_path = count($page_path);
	
	#------------------------------------------------------------------
	# course dropdown list
	#------------------------------------------------------------------
	$PRINT_OUTPUT .= "<TR>";
	$PRINT_OUTPUT .= "<TD class=\"td2\">";
	$PRINT_OUTPUT .= "</TD>";
	$PRINT_OUTPUT .= "<TD class=\"td1\">";
	$PRINT_OUTPUT .= "<SPAN style=\"color:white\">PLEASE SELECT A COURSE: </SPAN>";
	$PRINT_OUTPUT .= "</TD>";
	$PRINT_OUTPUT .= "<TD class=\"td1\">";
	$PRINT_OUTPUT .= "<div id=\"div_course\">";
	$PRINT_OUTPUT .= "<select name=\"select_course\" id=\"select_course\" CLASS=\"dropdownlist\" onchange=\"Goto(this.value)\">";
	$PRINT_OUTPUT .= "<option value=\"clear\" selected=\"selected\">select...</option>";
	
	if($length_path >= 1){
		
		$ob_page = getPageDetails($page_path[0]);
		
		$name_page = $ob_page -> getData('p_name');
		
		$id_page = $page_path[0];
		
		$PRINT_OUTPUT .= "<option value=\"".$id_page."\" onclick=\"Goto('".$id_page."')\" selected=\"selected\">".$name_page."</option>";
		
	}
	
	$PRINT_OUTPUT .= "</select></div></TD></TR>";
	
	#------------------------------------------------------------------
	# module dropdown list
	#------------------------------------------------------------------
	
	$PRINT_OUTPUT .= "<TR>";
	$PRINT_OUTPUT .= "<TD class=\"td2\">";
	$PRINT_OUTPUT .= "</TD>";
	$PRINT_OUTPUT .= "<TD class=\"td1\">";
	$PRINT_OUTPUT .= "<SPAN style=\"color:white\">PLEASE SELECT A MODULE: </SPAN>";
	$PRINT_OUTPUT .= "</TD>";
	$PRINT_OUTPUT .= "<TD class=\"td1\">";
	$PRINT_OUTPUT .= "<div id=\"div_course\">";
	$PRINT_OUTPUT .= "<select name=\"select_module\" id=\"select_module\" CLASS=\"dropdownlist\" onchange=\"Goto(this.value)\">";

	if($length_path >= 1){

		$array_module = $PAGES -> getChildrenOfPage($page_path[0]);
		
		$PRINT_OUTPUT .= "<option value=\"clear\" selected=\"selected\">select...</option>"; //
		
		foreach($array_module -> getPageIDs() as $module_page_id){
			
			# Get page details
			$module_page = $array_module -> getPage($module_page_id);

			# Get list of groups authorized to view this page
			$module_page_authorized = explode(",", $module_page -> getData("p_access"));
			
			# Get List of groups of users
			$module_group_authorized= explode(",", $USER -> getGroup());

			# Ensure it can be viewed at current authorization
			$module_page_authorized = $USER -> isUserAuthorized($PAGES -> getAuthorizedGroups($module_page_id));

			# Ensure it's in the navigation
			$module_page_in_navigation = ($module_page -> getData("p_innavigation") == "1");
			
			if($module_page_authorized && $module_page_in_navigation){
				
				if($page_path[1] == $module_page_id){
					
					$PRINT_OUTPUT .= "<option value=\"".$module_page -> getData("p_id")."\" onclick=\"Goto('".$module_page -> getData("p_id")."')\" selected=\"selected\">".$module_page -> getData("p_name")."</option>";
				}
				else{
					
					$PRINT_OUTPUT .= "<option value=\"".$module_page -> getData("p_id")."\" onclick=\"Goto('".$module_page -> getData("p_id")."')\">".$module_page -> getData("p_name")."</option>";
				}
		
				
			}
		}
	}
	
	$PRINT_OUTPUT .= "</select></div></TD></TR>";
	
	#------------------------------------------------------------------
	# page dropdown list
	#------------------------------------------------------------------
	
	$PRINT_OUTPUT .= "<TR>";
	$PRINT_OUTPUT .= "<TD class=\"td2\">";
	$PRINT_OUTPUT .= "</TD>";
	$PRINT_OUTPUT .= "<TD class=\"td1\">";
	$PRINT_OUTPUT .= "<SPAN style=\"color:white\">PLEASE SELECT A PAGE: </SPAN>";
	$PRINT_OUTPUT .= "</TD>";
	$PRINT_OUTPUT .= "<TD class=\"td1\">";
	$PRINT_OUTPUT .= "<div id=\"div_course\">";
	$PRINT_OUTPUT .= "<select name=\"select_page\" id=\"select_page\" CLASS=\"dropdownlist\" onchange=\"Goto(this.value)\">";

	$id_previous = "";
	$id_next = "";
	$id_always_previous = "";
	$id_tmp_previous = "";
	
	
	if($length_path >= 2){
		
		$array_module = $PAGES -> getChildrenOfPage($page_path[1]);
		
		$PRINT_OUTPUT .= "<option value=\"clear\" selected=\"selected\">select...</option>";
		
		$index = 0;
		
		foreach($array_module -> getPageIDs() as $module_page_id){
			
			# Get page details
			$module_page = $array_module -> getPage($module_page_id);

			# Get list of groups authorized to view this page
			$module_page_authorized = explode(",", $module_page -> getData("p_access"));
			
			# Get List of groups of users
			$module_group_authorized= explode(",", $USER -> getGroup());

			# Ensure it can be viewed at current authorization
			$module_page_authorized = $USER -> isUserAuthorized($PAGES -> getAuthorizedGroups($module_page_id));

			# Ensure it's in the navigation
			$module_page_in_navigation = ($module_page -> getData("p_innavigation") == "1");
			
			if($module_page_authorized && $module_page_in_navigation){
				
				if($id == $module_page_id){
					
					$id_tmp_previous = $id_always_previous;
					
					$id_previous = $id_always_previous;
					
					$PRINT_OUTPUT .= "<option value=\"".$module_page -> getData("p_id")."\" onclick=\"Goto('".$module_page -> getData("p_id")."')\" selected=\"selected\">".$module_page -> getData("p_name")."</option>";
					
					if($index = count($array_module -> getPageIDs())-1){
						
						$id_next = "";
					}
				}
				else{
					
					if($id_tmp_previous != "" || $index == 1){
														
						$id_next = $module_page_id;	

						$id_tmp_previous = "";
					}
		
					$PRINT_OUTPUT .= "<option value=\"".$module_page -> getData("p_id")."\" onclick=\"Goto('".$module_page -> getData("p_id")."')\">".$module_page -> getData("p_name")."</option>";
				}
				
				$id_always_previous = $module_page_id;
				
				$index ++;
			}
		}
		
	}
	
	$PRINT_OUTPUT .= "</select></div></TD></TR>";
	
	$PRINT_OUTPUT .= "</TABLE></div>";
	  
	$PRINT_OUTPUT .= "</div>";
	
	# RIGHT
	$PRINT_OUTPUT .= "<div id=\"ContentBackground\"><div id=\"frame_ContentBackground\"><div id=\"div_ContentBackground\">";
	  
	# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    # P A G E   C O N T E N T
	# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	  
	if (!isset($main_output)) {
		
		$PAGE = getPageDetails($id);
		
		$PAGE_CONTENT = $PAGE -> getData("p_content");
		# Prep content
		$main_output = parseFlashLinks(parseFlashXML($PAGE_CONTENT));
		
		grabImages($main_output);
		
		#Change the original hyper link style to the one with css
		$main_output = ChangeHyperLinkStyle($main_output);
		
		$multiple_choice_searching_item_begin="<multiple-choice>";
		
		$multiple_choice_searching_item_end="</multiple-choice>";
		
		if(strpos($main_output,$multiple_choice_searching_item_begin)&& strpos($main_output,$multiple_choice_searching_item_begin)){
			
			$main_output=ReplaceMulitpleChoice($main_output,false);
		}
		
		$seaching_content = getRecord("SELECT gl_letter,gl_term,gl_descripto FROM " . $PROJECT_DB_TABLES["glossary"] . " order by gl_letter");
		
		//echo "SELECT gl_letter,gl_term,gl_descripto FROM " . $PROJECT_DB_TABLES["glossary"] . " order by gl_letter"."<br/>";
		
		$question_searching_item = "<a href=\"www.uq.edu.au\">solution</a>";
		
		$main_output = str_replace($question_searching_item,"",$main_output);
		
		$main_output = ReplaceFontFamily($main_output);
		
		$main_output = marked_keyword_replace($main_output,$seaching_content);
		
		//print_r($seaching_content);
					
		$main_output = glossary_replace($main_output,$seaching_content);						  
		
		#remove the none link Indentifier
		$main_output = RemoveHyperlink($main_output,"***","###");
		
		#replace the reference indetifier.
		$main_output = Replace_reference($main_output);	
		
		$main_output = Replace_URL($main_output);
														
	}
	  
	# MAIN
	$PRINT_OUTPUT .= $main_output;
	
	$PRINT_OUTPUT .= "</div>";
	
	$PRINT_OUTPUT .= "</div>";
	
	$PRINT_OUTPUT .= "<div id=\"page_nav_bar\">";
	
	if($length_path >= 2){
		
		$array_module = $PAGES -> getChildrenOfPage($page_path[1]);
		
		if($id_previous!=""){
		
			$PRINT_OUTPUT .="<a id='a_previous' class='prenext' href=\"javascript:Goto('".$id_previous."');\">PREVIOUS</a>&nbsp";
		}
		
		$count = 1; 
		
		foreach($array_module -> getPageIDs() as $module_page_id){
			
			# Get page details
			$module_page = $array_module -> getPage($module_page_id);

			# Get list of groups authorized to view this page
			$module_page_authorized = explode(",", $module_page -> getData("p_access"));
			
			# Get List of groups of users
			$module_group_authorized= explode(",", $USER -> getGroup());

			# Ensure it can be viewed at current authorization
			$module_page_authorized = $USER -> isUserAuthorized($PAGES -> getAuthorizedGroups($module_page_id));

			# Ensure it's in the navigation
			$module_page_in_navigation = ($module_page -> getData("p_innavigation") == "1");
			
			if($module_page_authorized && $module_page_in_navigation){
				
				if($id == $module_page_id){
					
					$PRINT_OUTPUT .= "<a href=\"javascript:select_page_changed('".$module_page_id."','page',true);\" title=\"".$module_page -> getData("p_name")."\" onclick=\"Goto('".$module_page_id."');\"><img width=\"18px\" id=\"img".$count."\" src=\"../icon/buttons/pink".$count.".png\" border=\"0\"/></a>&nbsp;";
				}
				else{
		
					$PRINT_OUTPUT .= "<a href=\"javascript:select_page_changed('".$module_page_id."','page',true);\" title=\"".$module_page -> getData("p_name")."\" onclick=\"Goto('".$module_page_id."');\"><img width=\"18px\" id=\"img".$count."\" src=\"../icon/buttons/grey".$count.".png\" border=\"0\"/></a>&nbsp;";
				}
				
				$count ++;
			}
		}	
		
		if($id_next != ""){

			$PRINT_OUTPUT .="<a id='a_next' class='prenext' href=\"javascript:Goto('".$id_next."');\">NEXT</a>&nbsp;";
		}
		
	}
	  
	$PRINT_OUTPUT .= "</div>";
	
	$PRINT_OUTPUT .= "</div>";
	
	$PRINT_OUTPUT .= "<div id=\"uqfooter\">";
	
	$PRINT_OUTPUT .= "<div id=\"footerleft\">";
	
	$PRINT_OUTPUT .= "<a>GlOSSARY</a>&nbsp;&nbsp;";
	
	$PRINT_OUTPUT .= "|";
	
	$PRINT_OUTPUT .= "&nbsp;&nbsp;<a>REFERENCE</a>";
	
	$PRINT_OUTPUT .= "</div>";
	
	$PRINT_OUTPUT .= "<div id=\"footerright\">";
	
	$PRINT_OUTPUT .= "<a>CREDITS</a>&nbsp;&nbsp;";
	
	$PRINT_OUTPUT .= "|";
	
	$PRINT_OUTPUT .= "&nbsp;&nbsp;<a>PRINT</a>&nbsp;&nbsp;";
	
	$PRINT_OUTPUT .= "|";
	
	$PRINT_OUTPUT .= "&nbsp;&nbsp;<a>HELP</a>&nbsp;&nbsp;";
	
	$PRINT_OUTPUT .= "|";
	
	$PRINT_OUTPUT .= "&nbsp;&nbsp;<a>LOGOUT</a>";
	
	$PRINT_OUTPUT .= "</div>";
	
	$PRINT_OUTPUT .= "</div>";
	
	$PRINT_OUTPUT .= "<div id=\"popup\" >";

	$PRINT_OUTPUT .= "<div id=\"handle\" style=\"\">";
 
    $PRINT_OUTPUT .= "<form name=\"popupform\" id=\"popupform\" action=\"" . $id . ".php\" method=\"get\">";
 
 	$PRINT_OUTPUT .= "</form>";
 
 	$PRINT_OUTPUT .= "</div>";
	
	$PRINT_OUTPUT .= "</div>";
	
	$PRINT_OUTPUT .= "</body>";
	
	$PRINT_OUTPUT .= "</html>";
	
	if(deleteFile("../files/".$course_id."/html/",$id.".html")){
		
		echo date("H:i:s")."------"."../files/".$course_id."/html/",$id.".html has been deleted"."<br/><br/>";
	}
	else{
		
		echo date("H:i:s")."------"."../files/".$course_id."/html/",$id.".html deleting is not successful"."<br/><br/>";
	}
	
	//echo $PRINT_OUTPUT;
	if(createFile("../files/".$course_id."/html/",$id.".html",$PRINT_OUTPUT)){
	
		echo date("H:i:s")."------"."../files/".$course_id."/html/",$id.".html has been created"."<br/><br/>";		 
	}
	else{
		
		echo date("H:i:s")."------"."../files/".$course_id."/html/",$id.".html creation request has been rejected"."<br/><br/>";
	}
}

#Iteration function to generate left side menu	
function IterationList($pages,$page_id){

	global $content_left_side;
	global $USER;
	global $PAGES;
	global $page_path;
	global $current_id;
	
	$PAGE_ID = $current_id;
	
	$content_left_side .= "<ul>";
	
	if(count($pages)>0) {
		
		foreach($pages -> getPageIDs() as $lsm_page_id){
			
			$lsm_page = $pages -> getPage($lsm_page_id);
			
			$lsm_page_authorized = explode(",", $lsm_page -> getData("p_access"));
			
			$lsm_group_authorized = explode(",", $USER -> getGroup());
			
			# Ensure it can be viewed at current authorization
			$lsm_page_authorized = $USER -> isUserAuthorized($PAGES -> getAuthorizedGroups($lsm_page_id));
			
			$lsm_page_in_navigation = ($lsm_page -> getData("p_innavigation") == "1");

			if ($lsm_page_authorized && $lsm_page_in_navigation) {
				
//				echo $lsm_page_id."___".$PAGE_ID."<br/>";
//				
//				print_r($page_path);
//				
//				echo "<br/>";
				
				if(in_array($lsm_page_id,$page_path)||$lsm_page_id==$PAGE_ID){
					
					if($lsm_page_id==$PAGE_ID){
						
						$content_left_side .= "<li><a href=\"".$lsm_page -> getData("p_id").".html\" style=\"font-family:Georgia,serif;color:#DF0101;\">" . $lsm_page -> getData("p_name") . "</a></li>";
					}
					else{
						
						$content_left_side .= "<li><a href=\"".$lsm_page -> getData("p_id").".html\" style=\"font-family:Georgia,serif;color:#4B088A;text-decoration: none;\">" . $lsm_page -> getData("p_name") . "</a></li>";
					}
					$next_level_pages = $PAGES -> getChildrenOfPage($lsm_page_id);
					
					echo "<br/>";
					
					IterationList($next_level_pages,$lsm_page_id);
				}
				else if($lsm_page_id!=$PAGE_ID&&!in_array($lsm_page_id,$page_path)){
					
					$content_left_side .= "<li><a href=\"" .$lsm_page -> getData("p_id").".html\" style=\"font-family:Georgia,serif;color:#4B088A;text-decoration: none;\">" . $lsm_page -> getData("p_name") . "</a></li>";
				}
			}
		}
		
	}
	
	$content_left_side .= "</ul>";
	
}

function grabImages($content){
	
	global $course_id;
	preg_match_all("#src\=\"(.+?)\"#", $content, $matches);
	
	foreach($matches[1] as $matches_data){
		
		$name_file = str_replace("../assets/uploads/","",$matches_data);
		
		if(deleteFile("../files/".$course_id."/image/".$name_file)){
		
			echo date("H:i:s")."------"."../files/".$course_id."/image/".$name_file." has been deleted"."<br/><br/>";
		}
		else{
		
			echo date("H:i:s")."------"."../files/".$course_id."/image/".$name_file." deleting is not successful"."<br/><br/>";
		}
	
		//echo $PRINT_OUTPUT;
		if(copy($matches_data,"../files/".$course_id."/image/".$name_file)){
	
			echo date("H:i:s")."------"."../files/".$course_id."/image/".$name_file." has been pasted"."<br/><br/>";		 
		}
		else{
		
			echo date("H:i:s")."------"."../files/".$course_id."/image/".$name_file." copy request has been rejected"."<br/><br/>";
		}
	}
}


?>